home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
HPAVC
/
HPAVC CD-ROM.iso
/
MCASM.RAR
/
MC_ASM.EXE
/
WROX_ASM
/
CH13
/
C13_1.ASM
next >
Wrap
Assembly Source File
|
1994-11-23
|
1KB
|
62 lines
;
; Program 13.1 Handling Conventional Memory via DOS
;
.286
dosseg
.model small
.stack 100h
.data
ptr1 dw ?
.code
; When a program starts DS and ES both point to PSP.
; I use unmodified ES as segment address of the beginning of
; the program space.
Start:
mov ax,@data
mov ds,ax ; Load data segment
mov bx,ss
sub bx,ax
shl bx,4
cli
mov ss,ax ; Load stack pointer
add sp,bx
sti
mov bx,sp
add bx,15 ; Round up to next paragraph
shr bx,4
add ax,bx ; AX = SS + SP / 16 = segment address
; of the end of the program space
mov bx,es
sub ax,bx ; AX = required ammount of paragraphs
mov bx,ax
mov ah,4ah
int 21h ; Resize block
jc Resize_Error
mov ah,48h ; Allocate
mov bx,1000 ; 16K
int 21h
jc Alloc_Error
mov ptr1,ax
; . . .
mov ah,4Ah ; Resize up to
mov bx,2000 ; 32K
mov es,ptr1
int 21h
jc Resize_Error
; . . .
mov ah,49h ; Free block
mov es,ptr1
int 21h
jc Free_Error
xor al,al ; Successful
Resize_Error:
Alloc_Error:
Free_Error:
mov ah,4ch
int 21h
end Start